package com.spark.mooc.ch2_scala.part02_objectOrientedProgramming

/**
 * @description:
 * @time: 2020/11/24 14:47
 * @author: lhy
 */
class Bus(val brand:String,val price:Int){
    def info(): Unit ={
        println(s"Car brand is $brand and price is $price")
    }
}
object Bus{
    def apply(brand:String,price:Int): Bus ={
        println("Debug:calling apply......")
        new Bus(brand,price)
    }
    def unapply(b:Bus) :Option[(String,Int)] = {
        println("Debug:calling unapply......")
        Some((b.brand,b.price))
    }
}
object TestUnapply {
    def main(args: Array[String]): Unit = {
        val Bus(busBrand,busPrice) = Bus("BMW",800000)
        println("brand:" + busBrand + "and carPrice:" + busPrice)
    }
}
